/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.opencvjava.piano;

import com.google.common.collect.Lists;
import com.opencvjava.piano.support.SourceMat;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

import static com.opencvjava.support.util.CvUtils.imshow;
import static com.opencvjava.support.util.CvUtils.mat;
import static org.opencv.core.Core.BORDER_CONSTANT;
import static org.opencv.core.Core.BORDER_DEFAULT;
import static org.opencv.core.Core.NORM_MINMAX;
import static org.opencv.core.Core.add;
import static org.opencv.core.Core.copyMakeBorder;
import static org.opencv.core.Core.dft;
import static org.opencv.core.Core.getOptimalDFTSize;
import static org.opencv.core.Core.log;
import static org.opencv.core.Core.magnitude;
import static org.opencv.core.Core.merge;
import static org.opencv.core.Core.normalize;
import static org.opencv.core.CvType.CV_8UC1;
import static org.opencv.imgproc.Imgproc.GaussianBlur;

/**
 * @author : sunzb
 * @date: 2019/11/27
 */
@Service
public class Extract3 {
    private final Logger logger = LoggerFactory.getLogger(Extract3.class);
    private Random random = new Random();
    @Autowired
    SourceMat sourceMat;

    public void test() {
        sourceMat.read("1.jpg");
//        sourceMat.read("2.png");
//        sourceMat.read("3.png");
//        sourceMat.read("4.jpg");
        sourceMat.verify();
        sourceMat.process();
        logger.warn("谱线数量:" + sourceMat.getLineRowIndexes().size());
        Mat src = sourceMat.getSrc();
        byte[] data = sourceMat.getData();
        byte[] dataLine = sourceMat.getDataLine();
        byte[] dataNoLine = sourceMat.getDataNoLine();

        Mat bin = new Mat(src.size(), CV_8UC1);
        bin.put(0, 0, data);
        Mat matLine = new Mat(src.size(), CV_8UC1);
        matLine.put(0, 0, dataLine);
        Mat matNoLine = new Mat(src.size(), CV_8UC1);
        matNoLine.put(0, 0, dataNoLine);
        imshow("源图", src);
        imshow("二值化", bin);
        imshow("带谱线", matLine);
        imshow("不带谱线", matNoLine);
    }
}
